﻿using lingopen.Application;
using lingopen.Application.System;
using lingopen.Entity.System;
using Microsoft.AspNetCore.Mvc;

namespace lingopen.Jabil.Server.Areas.SystemManage.Controllers
{
    [Area(AreaNames.SystemManage)]
    [LoginAuthorizeAttribute]
    public class DepartmentController : WebController
    {
        public ActionResult Index()
        {
            return View();
        }
        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="pagination">页码</param>
        /// <param name="keyword">关键字</param>
        /// <returns></returns>
        [HttpGet]
        public ActionResult GetModels(Pagination pagination, string keyword)
        {
            PagedData<Sys_Department> data = this.CreateService<IDepartmentAppService>().GetDepartments(pagination,keyword);
            return this.UISuccessData(data);
        }

        [HttpPost]
        //[ValidateAntiForgeryToken]
        public ActionResult Add(AddDepartmentInput input)
        {
            input.CreateUserId = this.CurrentSession.UserId;
            this.CreateService<IEntityAppService>().AddFromDto<Sys_Department, AddDepartmentInput>(input);
            return this.UISuccessData();
        }
        [HttpPost]
        //[ValidateAntiForgeryToken]
        public ActionResult Update(UpdateDepartmentInput input)
        {
            this.CreateService<IEntityAppService>().UpdateFromDto<Sys_Department, UpdateDepartmentInput>(input);
            return this.UISuccessData();
        }

        [HttpPost]
        //[ValidateAntiForgeryToken]
        public ActionResult Delete(string id)
        {
            this.CreateService<IEntityAppService>().SoftDelete<Sys_Department>(id, this.CurrentSession.UserId);
            return this.UISuccessData();
        }
    }

}